package com.danjinwulian.web.controller.iot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.danjinwulian.common.core.domain.entity.IotTenantPower;
import com.danjinwulian.device.service.IIotTenantPowerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danjinwulian.common.annotation.Log;
import com.danjinwulian.common.core.controller.BaseController;
import com.danjinwulian.common.core.domain.AjaxResult;
import com.danjinwulian.common.enums.BusinessType;
import com.danjinwulian.common.utils.poi.ExcelUtil;
import com.danjinwulian.common.core.page.TableDataInfo;

/**
 * 住客用电Controller
 * 
 * @author ken.h
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/device/power")
public class IotTenantPowerController extends BaseController
{
    @Autowired
    private IIotTenantPowerService iotTenantPowerService;

    /**
     * 查询住客用电列表
     */
    @PreAuthorize("@ss.hasPermi('device:power:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotTenantPower iotTenantPower)
    {
        startPage();
        List<IotTenantPower> list = iotTenantPowerService.selectIotTenantPowerList(iotTenantPower);
        return getDataTable(list);
    }

    /**
     * 导出住客用电列表
     */
    @PreAuthorize("@ss.hasPermi('device:power:export')")
    @Log(title = "住客用电", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotTenantPower iotTenantPower)
    {
        List<IotTenantPower> list = iotTenantPowerService.selectIotTenantPowerList(iotTenantPower);
        ExcelUtil<IotTenantPower> util = new ExcelUtil<IotTenantPower>(IotTenantPower.class);
        util.exportExcel(response, list, "住客用电数据");
    }

    /**
     * 获取住客用电详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:power:query')")
    @GetMapping(value = "/{tenantPowerId}")
    public AjaxResult getInfo(@PathVariable("tenantPowerId") Long tenantPowerId)
    {
        return AjaxResult.success(iotTenantPowerService.selectIotTenantPowerByTenantPowerId(tenantPowerId));
    }

    /**
     * 新增住客用电
     */
    @PreAuthorize("@ss.hasPermi('device:power:add')")
    @Log(title = "住客用电", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotTenantPower iotTenantPower)
    {
        return toAjax(iotTenantPowerService.insertIotTenantPower(iotTenantPower));
    }

    /**
     * 修改住客用电
     */
    @PreAuthorize("@ss.hasPermi('device:power:edit')")
    @Log(title = "住客用电", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotTenantPower iotTenantPower)
    {
        return toAjax(iotTenantPowerService.updateIotTenantPower(iotTenantPower));
    }

    /**
     * 删除住客用电
     */
    @PreAuthorize("@ss.hasPermi('device:power:remove')")
    @Log(title = "住客用电", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenantPowerIds}")
    public AjaxResult remove(@PathVariable Long[] tenantPowerIds)
    {
        return toAjax(iotTenantPowerService.deleteIotTenantPowerByTenantPowerIds(tenantPowerIds));
    }
}
